﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using YXShop.Common;
using System.Collections.Generic;

namespace YXShop.Web.admin.store
{
    public partial class storeask_view : System.Web.UI.Page
    {
        YXShop.BLL.Store.StoreAsk storeAskBll = new YXShop.BLL.Store.StoreAsk();
        YXShop.BLL.Store.StoreAnswer storeAnswerBLL = new BLL.Store.StoreAnswer();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                YXShop.Common.PromptInfo.Popedom("014005001");
                YXShop.Model.Admin.AdminInfo admin = YXShop.Common.AdministrorManager.Get();
                YXShop.BLL.Admin.Administrators adminBLL = new BLL.Admin.Administrators();
                int id = ChangeHope.WebPage.PageRequest.GetQueryInt("id");
                if (id > 0)
                {
                    YXShop.Model.Store.StoreAsk ask = storeAskBll.GetModelById(id);
                    lblMessageTitle.Text = ask.MessageTitle;
                    litMessage.Text = ask.Message;
                    lblAnswerCount.Text = ask.Answercount.ToString();
                    if (ask.ReceiveType == 1)
                    {
                        lblReceiver.Text = "总部";
                    }
                    else if (ask.ReceiveType == 2)
                    {
                        lblReceiver.Text = "销售中心：";
                        YXShop.BLL.Store.StoreCenter scBLL = new BLL.Store.StoreCenter();
                        lblReceiver.Text += scBLL.GetModelById(ask.ReceiveStoreCenterId.Value).StoreCentername;
                    }
                    else if (ask.ReceiveType == 3)
                    {
                        lblReceiver.Text = "门店：";
                        YXShop.BLL.Store.Store sBLL = new BLL.Store.Store();
                        lblReceiver.Text += sBLL.GetModelById(ask.ReceiveStoreId.Value).Storename;
                    }
                    lblSender.Text = adminBLL.GetModel(ask.SenderId.Value).Name;
                    lblSenderTime.Text = ask.SenderTime.ToString();

                    lblAnswer.Text=GetAnswerList(id);

                    HyperLink1.NavigateUrl += "?askid=" + ask.Id;

                }

            }
        }

        private string GetAnswerList(int askid)
        {
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();

            string where = " and answer.askid=" + askid.ToString();
            ChangeHope.DataBase.DataByPage dataPage = storeAnswerBLL.GetList(where);
            table.AddHeadCol("", "");
            table.AddHeadCol("", "回复人");
            table.AddHeadCol("", "回复内容");
            table.AddHeadCol("", "回复时间");
            table.AddRow();
            if (dataPage.DataReader != null)
            {
                int curpage = ChangeHope.WebPage.PageRequest.GetInt("pageindex");
                if (curpage < 0)
                {
                    curpage = 1;
                }
                int count = 0;
                YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();

                while (dataPage.DataReader.Read())
                {
                    count++;
                    string No = (15 * (curpage - 1) + count).ToString();
                    table.AddCol("");
                    table.AddCol(dataPage.DataReader["name"].ToString());
                    table.AddCol(dataPage.DataReader["message"].ToString());
                    table.AddCol(dataPage.DataReader["answertime"].ToString());
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }
    }
}
